﻿Public Class ClsTBalanceQuantityDbAccess
    Inherits ClsBaseDbAccess

    Public Sub New(ByVal s As String)
        MyBase.New(s, TABLE_NAME_T_BALANCE_QUANTITY)
    End Sub

    Public Sub New(ByVal s As String, ByVal n As String)
        MyBase.New(s, n)
    End Sub

    ''' <summary>
    ''' 删除指定期间的科目余额
    ''' </summary>
    ''' <param name="wp"></param>
    ''' <returns></returns>
    Public Function DeleteBalanceByWorkPeriod(ByVal wp As String) As Integer

        Dim tmpRetInt As Integer

        Try

            Dim tmpSql As String
            Dim tmpParas(0) As OleDb.OleDbParameter
            Dim tmpDbAccess = GetConnection()

            '打开数据库
            tmpDbAccess.DbOpen()

            '构造查询语句
            tmpSql = "Delete * from [" & Me.AppTableName & "] "
            tmpSql &= "where  [WorkPeriod]=@WorkPeriod "

            tmpParas(0) = New OleDb.OleDbParameter("@WorkPeriod", OleDb.OleDbType.VarWChar)
            tmpParas(0).Value = wp

            tmpRetInt = tmpDbAccess.UpdateRecord(tmpSql, tmpParas)

            '关闭数据库
            tmpDbAccess.DbClose()

        Catch ex As OleDb.OleDbException

            mErrorNumber = ex.ErrorCode
            mErrorMessage = ex.Message
            mErrorCreater = "ClsTBalanceQuantityDbAccess - DeleteBalanceByWorkPeriod"

        End Try

        Return tmpRetInt

    End Function

    Public Overrides Function ConvertRecordToClass(reader As OleDb.OleDbDataReader) As Object
        If reader Is Nothing Then
            Return Nothing
        End If

        Dim tmpList As List(Of ClsTBalanceQuantity) = New List(Of ClsTBalanceQuantity)

        Try

            Dim tmpCls As ClsTBalanceQuantity

            While reader.Read()

                tmpCls = New ClsTBalanceQuantity()

                With tmpCls

                    .BalanceId = ConvertDbNullInteger(reader(0))
                    .WorkPeriod = ConvertDbNullString(reader(1))
                    .AcctCode = ConvertDbNullString(reader(2))
                    .AcctLevel = ConvertDbNullInteger(reader(3))
                    .IfLastLevel = reader.GetBoolean(4)
                    .AcctName = ConvertDbNullString(reader(5))
                    .Year = ConvertDbNullSingle(reader(6))
                    .YearPrice = ConvertDbNullDecimal(reader(7))
                    .YearMoney = ConvertDbNullDecimal(reader(8))
                    .BeginBalance = ConvertDbNullSingle(reader(9))
                    .BeginPrice = ConvertDbNullDecimal(reader(10))
                    .BeginMoney = ConvertDbNullDecimal(reader(11))
                    .CreditSum = ConvertDbNullSingle(reader(12))
                    .CreditPrice = ConvertDbNullDecimal(reader(13))
                    .CreditSumMoney = ConvertDbNullDecimal(reader(14))
                    .CreditTotal = ConvertDbNullSingle(reader(15))
                    .CreditTotalPrice = ConvertDbNullDecimal(reader(16))
                    .CreditTotalMoney = ConvertDbNullDecimal(reader(17))
                    .DebitSum = ConvertDbNullSingle(reader(18))
                    .DebitSumPrice = ConvertDbNullDecimal(reader(19))
                    .DebitSumMoney = ConvertDbNullDecimal(reader(20))
                    .DebitTotal = ConvertDbNullSingle(reader(21))
                    .DebitTotalPrice = ConvertDbNullDecimal(reader(22))
                    .DebitTotalMoney = ConvertDbNullDecimal(reader(23))
                    .Balance = ConvertDbNullSingle(reader(24))
                    .BalancePrice = ConvertDbNullDecimal(reader(25))
                    .BalanceMoney = ConvertDbNullDecimal(reader(26))
                    .BalanceDirection = ConvertDbNullString(reader(27))

                End With

                tmpList.Add(tmpCls)

            End While

        Catch ex As OleDb.OleDbException

            mErrorNumber = ex.ErrorCode
            mErrorMessage = ex.Message
            mErrorCreater = "ClsTBalanceQuantityDbAccess - ConvertRecordToClass"

        End Try

        Return tmpList

    End Function
End Class
